package com.theima.socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @program: Myset
 * @description: 发送端
 * @author: xuejingjing
 * @create: 2021-06-24 00:50
 **/
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //1,找码头 表示从10000端口接受数据，空参表示随机端口
        DatagramSocket ds = new DatagramSocket(10000);

        //2，创建一个新的箱子
         byte [] bytes = new byte[1024];
         DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        //3,接受礼物，把礼物当到新的箱子中
        ds.receive(dp);
        //4，从新的箱子里面获取礼物
        byte[] data = dp.getData();
        System.out.println(new String(data));
        //5，拿走走羊
        ds.close();


    }
}
